package com.jn.erp.wechat.staff.api.controller;

import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.web.api.course.entity.dto.TCourseDto;
import com.jn.erp.web.api.course.entity.vo.TCourseVo;
import com.jn.erp.web.api.course.service.TCourseService;
import com.jn.erp.wechat.common.api.controller.base.BaseWxAuthController;
import com.jn.erp.wechat.common.core.WxTableDataInfo;
import com.jn.erp.wechat.common.api.entity.dto.WxUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <pre>
 * 课程套餐 相关接口管理
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/9/29 19:52
 */
@RestController
@RequestMapping("/wx/course")
public class MpCourseController extends BaseWxAuthController {
    @Autowired
    private TCourseService tCourseService;

    //-------------------------------------课程---------------------
    /**
     课程列表    /tCourse/list
     */
    @GetMapping("list")
    public WxTableDataInfo list(TCourseVo tCourseVo){
        WxUserDto wxUser = getWxUser();
        //机构id
        tCourseVo.setOrgId(wxUser.getOrgIdLong());
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(getUserId()) );
        startPage();
        List<TCourseDto> list = tCourseService.courseList(tCourseVo);
        return getWxDataTable(list);
    }

    //-------------------------------------新建课程---------------------
    /**
     课程新建    /tCourse/save
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody TCourseVo tCourseVo){
        WxUserDto wxUser = getWxUser();
        //机构id
        tCourseVo.setOrgId(wxUser.getOrgIdLong());
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(wxUser.getUserId()) );
        String code = tCourseService.saveCourse(tCourseVo);
        return AjaxResult.success(code);
    }

    //-------------------------------------课程详情---------------------
    /**
     课程修改    /tCourse/update
     */
    @PostMapping("update")
    public AjaxResult update(@RequestBody TCourseVo tCourseVo){
        WxUserDto wxUser = getWxUser();
        //机构id
        tCourseVo.setOrgId(wxUser.getOrgIdLong());
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(wxUser.getUserId()) );
        String code = tCourseService.updateCourse(tCourseVo);
        return AjaxResult.success(code);
    }

    /**
     课程删除   /tCourse/delete
     */
    @PostMapping("delete")
    public AjaxResult delete(@RequestBody TCourseVo tCourseVo){
        WxUserDto wxUser = getWxUser();
        //机构id
        tCourseVo.setOrgId(wxUser.getOrgIdLong());
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(wxUser.getUserId()) );
        tCourseVo.setIsDelete("1");
        Boolean boo = tCourseService.deleteCourse(tCourseVo);
        return AjaxResult.success(boo);
    }
}
